package com.wyz.saas.app.set.ui

import android.graphics.Bitmap
import com.atom.annotation.Impl
import com.wyz.saas.api.set.AppSetDescriptor
import com.wyz.saas.api.set.AppSetter
import com.wyz.saas.app.R
import com.wyz.saas.common.set.AbstractAppSetDescriptorBoolean
import com.wyz.saas.common.utils.otherwise
import com.wyz.saas.common.utils.yes

@Impl(api = AppSetDescriptor::class)
class AppSetAuthSexDescirptor : AbstractAppSetDescriptorBoolean() {

    companion object {
        const val NAME = "mine_sex"
    }

    override fun getValueTip(value: Boolean): String {
        return value .yes { "男生" }.otherwise { "女生" }
    }

    override fun get(): Boolean? {
        val get = mApiContext.getImpl(AppSetter::class.java)?.get(NAME)
        if (get == null || get.isEmpty()) return null
        var equals = get.equals("true", ignoreCase = true)
        if (equals) {
            return true
        } else {
            if (get.equals("false", ignoreCase = true)) {
                return false
            }
        }
        return null
    }

    override fun put(t: Boolean) {
        mApiContext.getImpl(AppSetter::class.java)?.set(NAME, t)
    }


    override fun getTip(): String {
        return "性别"
    }

    override fun getGroup(): String {
        return "MINE"
    }

    override fun getIcon(): Bitmap? {
        return mApiContext.getBitmap(R.mipmap.icon_mine)
    }

    override fun getLabel(): String {
        return "我的性别"
    }
}